home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / boot / scsiDiskBoot / RCS / string.c,v < prev    next >
Encoding:
Text File  |  1989-06-08  |  7.5 KB  |  368 lines

  1. head     1.2;
  2. access   ;
  3. symbols  ;
  4. locks    ; strict;
  5. comment  @ * @;
  6.  
  7.  
  8. 1.2
  9. date     87.05.11.11.07.34;  author brent;  state Exp;
  10. branches ;
  11. next     1.1;
  12.  
  13. 1.1
  14. date     86.07.18.09.33.50;  author brent;  state Exp;
  15. branches ;
  16. next     ;
  17.  
  18.  
  19. desc
  20. @Slimline boot version of Sprite c library string.c
  21. @
  22.  
  23.  
  24. 1.2
  25. log
  26. @Commented out String_Length
  27. Commented out String_Copy
  28. @
  29. text
  30. @/* 
  31.  * string.c --
  32.  *
  33.  *    This file implements a whole bunch of routines for manipulating
  34.  *    strings, including copying, comparison, and searching.
  35.  *
  36.  * Copyright (C) 1985 Regents of the University of California
  37.  * All rights reserved.
  38.  */
  39.  
  40. #ifndef lint
  41. static char rcsid[] = "$Header: string.c,v 1.1 86/07/18 09:33:50 brent Exp $ SPRITE (Berkeley)";
  42. #endif not lint
  43.  
  44.  
  45. #include "sprite.h"
  46. #include "string.h"
  47.  
  48.  
  49. /*
  50.  *----------------------------------------------------------------------
  51.  *
  52.  * String_Copy  --
  53.  *
  54.  *    Copies a string from one location to another.
  55.  *
  56.  * Results:
  57.  *    The return value is a pointer to the new copy of the string.
  58.  *
  59.  * Side effects:
  60.  *    Dst is modified to hold a copy of src.  It is the caller's
  61.  *    responsibility to make sure that dst has enough space to
  62.  *    hold the copy.
  63.  *
  64.  *----------------------------------------------------------------------
  65.  */
  66. #ifdef notdef
  67. char *
  68. String_Copy(src, dst)
  69.     register char *src;        /* Place from which to copy. */
  70.     char *dst;            /* Place to store copy. */
  71. {
  72.     register char *copy = dst;
  73.  
  74.     do {
  75.     } while ((*copy++ = *src++) != 0);
  76.     return dst;
  77. }
  78. #endif notdef
  79.  
  80. /*
  81.  *----------------------------------------------------------------------
  82.  *
  83.  * String_NCopy --
  84.  *
  85.  *    Copies exactly n characters from src to dst.  If src doesn't
  86.  *    contain exactly n characters, then the last characters are
  87.  *    ignored (if src is too long) or filled with zeros (if src
  88.  *    is too short).  In the case of truncation, dstmay not be
  89.  *    null-terminated.
  90.  *
  91.  * Results:
  92.  *    The result is a pointer to the new string.
  93.  *
  94.  * Side effects:
  95.  *    Memory at *dst is modified.  The caller must ensure that the
  96.  *    destination is large enough to hold n characters.
  97.  *
  98.  *----------------------------------------------------------------------
  99.  */
  100. #ifdef notdef
  101. char *
  102. String_NCopy(n, src, dst)
  103.     register int n;        /* How many characters to place at dst. */
  104.     register char *src;        /* Source string. */
  105.     char *dst;            /* Destination area. */
  106. {
  107.     register char *copy = dst;
  108.  
  109.     if (n == 0) {
  110.     return dst;
  111.     }
  112.     do {
  113.     if ((*copy++ = *src) != 0) {
  114.         src += 1;
  115.     }
  116.     } while (--n > 0);
  117.     return dst;
  118. }
  119. #endif notdef
  120.  
  121. /*
  122.  *----------------------------------------------------------------------
  123.  *
  124.  * String_Cat --
  125.  *
  126.  *    Copy one string onto the end of another.
  127.  *
  128.  * Results:
  129.  *    The return value is a pointer to the concatenated result
  130.  *    (dst).
  131.  *
  132.  * Side effects:
  133.  *    The destination string is modified to hold the concatenation
  134.  *    of itself and the source string.
  135.  *
  136.  *----------------------------------------------------------------------
  137.  */
  138. #ifdef notdef
  139. char *
  140. String_Cat(src, dst)
  141.     register char *src;        /* Source string. */
  142.     char *dst;            /* Destination string:  *srcPtr gets added
  143.                  * onto the end of this.
  144.                  */
  145. {
  146.     register char *copy = dst;
  147.  
  148.     do {
  149.     } while (*copy++ != 0);
  150.     copy -= 1;
  151.     do {
  152.     } while ((*copy++ = *src++) != 0);
  153.     return dst;
  154. }
  155. #endif
  156.  
  157. /*
  158.  *----------------------------------------------------------------------
  159.  *
  160.  * String_NCat --
  161.  *
  162.  *    Copy one string onto the end of another, with a limit on
  163.  *    how many bytes to copy.
  164.  *
  165.  * Results:
  166.  *    The return value is a pointer to the concatenated result
  167.  *    (dst).
  168.  *
  169.  * Side effects:
  170.  *    The destination string is modified to hold the concatenation
  171.  *    of itself and the source string.  If the source contains
  172.  *    more than n bytes, only the first n are copied.
  173.  *
  174.  *----------------------------------------------------------------------
  175.  */
  176. #ifdef notdef
  177. char *
  178. String_NCat(n, src, dst)
  179.     register int n;        /* Maximum number of chars to copy. */
  180.     register char *src;        /* Source string. */
  181.     char *dst;            /* Destination string:  the source gets added
  182.                  * onto the end of this.
  183.                  */
  184. {
  185.     register char *copy = dst;
  186.  
  187.     if (n == 0) {
  188.     return dst;
  189.     }
  190.  
  191.     do {
  192.     } while (*copy++ != 0);
  193.     copy -= 1;
  194.  
  195.     do {
  196.     if ((*copy++ = *src++) == 0) {
  197.         return dst;
  198.     }
  199.     } while (--n > 0);
  200.     *copy = 0;
  201.     return dst;
  202. }
  203. #endif
  204.  
  205. /*
  206.  *----------------------------------------------------------------------
  207.  *
  208.  * String_Compare --
  209.  *
  210.  *    Compares two strings lexicographically.
  211.  *
  212.  * Results:
  213.  *    The return value is 0 if the strings are identical, 1
  214.  *    if the first string is greater than the second, and 
  215.  *    -1 if the second string is less than the first.  If one
  216.  *    string is a prefix of the other then it is considered
  217.  *    to be less (the terminating zero byte participates in the
  218.  *    comparison).
  219.  *
  220.  * Side effects:
  221.  *    None.
  222.  *
  223.  *----------------------------------------------------------------------
  224.  */
  225.  
  226. int
  227. String_Compare(s1, s2)
  228.     register char *s1, *s2;        /* Strings to compare. */
  229. {
  230.     while (TRUE) {
  231.     if (*s1 != *s2) {
  232.         if (*s1 > *s2) {
  233.         return 1;
  234.         } else {
  235.         return -1;
  236.         }
  237.     }
  238.     if (*s1++ == 0) {
  239.         return 0;
  240.     }
  241.     s2 += 1;
  242.     }
  243. }
  244.  
  245. /*
  246.  *----------------------------------------------------------------------
  247.  *
  248.  * String_NCompare --
  249.  *
  250.  *    Compares two strings lexicographically.
  251.  *
  252.  * Results:
  253.  *    This procedure is identical to String_Compare, except
  254.  *    that it returns 0 as long as the two strings do not
  255.  *    differ in their first numChars characters.  If either
  256.  *    string is shorter than numChars characters then this
  257.  *    procedure is identical to String_Compare.
  258.  *
  259.  * Side effects:
  260.  *    None.
  261.  *
  262.  *----------------------------------------------------------------------
  263.  */
  264. #ifdef notdef
  265. int
  266. String_NCompare(numChars, s1, s2)
  267.     register int numChars;        /* Max number of chars to compare. */
  268.     register char *s1, *s2;        /* Strings to compare. */
  269. {
  270.     for ( ; numChars > 0; numChars -= 1) {
  271.     if (*s1 != *s2) {
  272.         if (*s1 > *s2) {
  273.         return 1;
  274.         } else {
  275.         return -1;
  276.         }
  277.     }
  278.     if (*s1++ == 0) {
  279.         return 0;
  280.     }
  281.     s2 += 1;
  282.     }
  283.     return 0;
  284. }
  285. #endif
  286.  
  287. /*
  288.  *----------------------------------------------------------------------
  289.  *
  290.  * String_Length --
  291.  *
  292.  *    Computes the number of characters in a string.
  293.  *
  294.  * Results:
  295.  *    The return value is the number of characters in the
  296.  *    string, not including the terminating zero byte.
  297.  *
  298.  * Side effects:
  299.  *    None.
  300.  *
  301.  *----------------------------------------------------------------------
  302.  */
  303. #ifdef notdef
  304. int
  305. String_Length(string)
  306.     register char *string;        /* String whose length is wanted. */
  307. {
  308.     register int result = -1;
  309.  
  310.     do {
  311.     result += 1;
  312.     } while (*string++ != 0);
  313.     return result;
  314. }
  315. #endif notdef
  316.  
  317. /*
  318.  *----------------------------------------------------------------------
  319.  *
  320.  * String_NLength --
  321.  *
  322.  *    This is identical to String_Length except that it will return N
  323.  *    if the string length reaches N.
  324.  *
  325.  * Results:
  326.  *    The return value is the number of characters in the
  327.  *    string, not including the terminating zero byte.
  328.  *
  329.  * Side effects:
  330.  *    None.
  331.  *
  332.  *----------------------------------------------------------------------
  333.  */
  334. #ifdef notdef
  335. int
  336. String_NLength(numChars, string)
  337.     int           numChars;        /* Maximum number of chars to check. */
  338.     register char *string;        /* String whose length is wanted. */
  339. {
  340.     register int result = -1;
  341.  
  342.     do {
  343.     result += 1;
  344.     } while (result < numChars && *string++ != 0);
  345.     return result;
  346. }
  347. #endif
  348. @
  349.  
  350.  
  351. 1.1
  352. log
  353. @Initial revision
  354. @
  355. text
  356. @d12 1
  357. a12 1
  358. static char rcsid[] = "$Header: string.c,v 1.4 86/04/24 11:03:41 nelson Exp $ SPRITE (Berkeley)";
  359. d37 1
  360. a37 1
  361.  
  362. d49 1
  363. d274 1
  364. a274 1
  365.  
  366. d286 1
  367. @
  368.